file_name='D:\\GITEE\\study_code\\Python\\2022-11-12\\learning_python.txt'
with open(file_name) as file_object:
    #第一次打印读取整个文件
    contents=file_object.read()
    print(contents.rstrip())
    print('\n')
     #第二次打印时遍历文件对象
with open(file_name) as file_object:
    for line in file_object:
        print(line.rstrip())
    print('\n')

    #第三次打印时将各行存储在一个列表中
with open(file_name) as file_object:
    lines=file_object.readlines()
#在with外的地方打印
for line in lines:
    modified_statesment=line.replace('Python','C')#将line字符串里的每一个Python替换为C
    print(modified_statesment.rstrip())

#发现：with语句会在展示文件完后自动关闭,replace语句改变的是返回值，而不是字符串本身
    for line in file_object:
        print(line.rstrip())
    print('\n')

   